package com.yc.damai.biz.impl;

import com.yc.damai.entity.DmOrderitem;
import com.yc.damai.entity.DmOrders;
import com.yc.damai.entity.DmProduct;
import com.yc.damai.mapper.DmOrderitemMapper;
import com.yc.damai.mapper.DmOrdersMapper;
import com.yc.damai.biz.IDmOrdersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yc.damai.mapper.DmProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 大麦商城-订单表-73 服务实现类
 * </p>
 *
 * @author ly
 * @since 2024-09-23
 */
@Service
public class DmOrdersServiceImpl extends ServiceImpl<DmOrdersMapper, DmOrders> implements IDmOrdersService {

    @Autowired
    DmOrderitemMapper orderitemMapper;
    @Autowired
    DmProductMapper productMapper;

    @Transactional
    @Override
    public void createPromotionOrder(DmOrders orders) {
        // 保存订单主表, 同时会返回数据库生成的主键(自增列) id
        save(orders);
        // 订单明细
        for (DmOrderitem item : orders.getItems()) {
            item.setOid(orders.getId());
            orderitemMapper.insert(item);
        }
        // TODO 请发送消息(email, 短信)给通知用户
        // 库存不用改
    }
}
